<!--任务管理-->
<template>
    <div class="rightCenter">
        <div class="listTop">
            <div class="listTopAddBut" @click="addClick()">
                新建任务
            </div>
            <!-- <div class="listTopInpBox">
                <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div>
                <input class="listTopInp" type="text" v-model='searchVal' oninput='searchFun' placeholder="搜索活动名称">
            </div> -->
        </div>
        <ul class="listUl">
            <li class="listLi fristLI">
                <div class="listDiv listOne">
                    任务编号
                </div>
                <div class="listDiv listTwo">
                    任务名称
                </div>
                <div class="listDiv listThree">
                    开始时间
                </div>
                <div class="listDiv listFour">
                    结束时间
                </div>
                <div class="listDiv listFive">
                    参与人数
                </div>
                <div class="listDiv listSix">
                    业务主
                </div>
                <div class="listDiv listSeven">
                    操作
                </div>
            </li>
            <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
                <div class="listDiv listOne">
                    {{item.id}}
                </div>
                <div class="listDiv listTwo">
                    {{item.name}}
                </div>
                <div class="listDiv listThree">
                    {{item.startTime}}
                </div>
                <div class="listDiv listFour">
                    {{item.expireTime}}
                </div>
                <div class="listDiv listFive">
                    {{item.limit}}
                </div>
                <div class="listDiv listSix">
                    {{item.ownerName}}
                </div>
                <div class="listDiv listSeven">
                    <div class="buttonBox audit" v-show='item.approval == "0" && item.permission % 7  == 0' @click='checkClick(index)'>
                        审核
                    </div>
                    <div class="buttonBox pass" v-show='item.approval == "1"'>
                        审核通过
                    </div>
                    <div class="buttonBox fail" v-show='item.approval == "2"'>
                        审核失败
                    </div>
                    <!-- <div class="buttonBox look" v-show='item.show != "edit"' @click='loogClick()'>
                        查看
                    </div> -->
                    <!--  v-show='item.permission % 3  == 0'  -->
                    <div class="buttonBox edit" @click='optionClick(index,1)'>
                        编辑
                    </div>
                    <div class="buttonBox delect" @click='optionClick(index,2)'>
                        删除
                    </div>
                </div>
            </li>
        </ul>
        <div class="paging">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
            </el-pagination>
        </div>
        <!-- 审核弹框 -->
        <div class="fixedBox" v-show='checkauditShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        请选择需要执行的操作
                    </div>
                    <div class="popuplistBoxTopBut" @click='checkCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='checkPassClick()'>
                        审核通过
                    </div>
                    <div class="popupCheckFail" @click='checkFailClick()'>
                        审核失败
                    </div>
                </div>
            </div>
        </div>
        <!-- 删除弹框 -->
        <div class="fixedBox" v-show='checkShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        确认要删除该消息吗？
                    </div>
                    <div class="popuplistBoxTopBut" @click='delectCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='delectOkClick()'>
                        确 认
                    </div>
                    <div class="popupCheckFail" @click='delectCancelClick()'>
                        取 消
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { mapActions } from "vuex";
import tasksRequest from "../../assets/tasks";
export default {
  data() {
    return {
      checkauditShow: false, // 审核弹框
      checkauditIndex: 0,
      checkShow: false, // 删除弹框
      delectIndex: 0,
      searchVal: "", //搜索
      pageSize: 10, //每页条数
      pageNo: 1, //页码
      totalVal: 0, //总数量
      dataList: []
    };
  },
  filters: {},
  created: function() {
    var self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "任务管理") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    } else {
      this.$router.push({
        path: "/login"
      });
      sessionStorage.clear();
      self.$message("暂无权限");
      return;
    }
    self.searchFun();
  },
  watch: {},
  mounted() {},
  methods: {
    // 审核
    checkClick(index) {
      this.checkauditIndex = index;
      this.checkauditShow = true;
    },
    // 审核通过
    async checkPassClick() {
      let self = this;
      this.checkauditShow = false;
      let params = {
        approval: 1,
        id: self.dataList[self.checkauditIndex].id
      };
      let res = await tasksRequest.gettaskupdateapproval(params);
      if (res.statusCode == 200) {
        self.$message("操作成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
      }
    },
    // 审核失败
    async checkFailClick() {
      let self = this;
      this.checkauditShow = false;
      let params = {
        approval: 2,
        id: self.dataList[self.checkauditIndex].id
      };
      let res = await tasksRequest.gettaskupdateapproval(params);
      if (res.statusCode == 200) {
        self.$message("操作成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
      }
    },
    //取消审核
    checkCancelClick() {
      this.checkauditShow = false;
    },
    // 消息详情
    optionClick(index, val) {
      if (val == 1) {
        this.$router.push({
          path: `/home/task/CompileEdit?id=${this.dataList[index].id}`
        });
      } else {
        this.delectIndex = index;
        this.checkShow = true;
      }
    },
    //确认删除
    async delectOkClick() {
      let self = this;
      let params = {
        taskId: self.dataList[self.delectIndex].id
      };
      let res = await tasksRequest.gettaskdelete(params);
      if (res.statusCode == 200) {
        self.$message("删除成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
      }
      this.checkShow = false;
    },
    //取消删除
    delectCancelClick() {
      this.checkShow = false;
    },
    //搜索
    async searchFun() {
      let self = this;
      let params = {
        page: self.pageNo,
        size: self.pageSize
      };
      let getParams = `page=${params.page}&size=${params.size}`;
      let res = await tasksRequest.gettasklist(getParams);
      if (res.statusCode == 200) {
        self.dataList = [];
        if (res.data) {
          if (res.data.records) {
            self.dataList = res.data.records;
          }
          self.totalVal = res.data.total * 1;
        }
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
    },
    //分页 - 每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchFun();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageNo = val;
      this.searchFun();
    },
    //添加
    addClick() {
      this.$router.push({
        path: "/home/task/edit"
      });
    },
    //查看
    loogClick() {}
  }
};
</script>
<style scoped>
.listOne {
  width: 12%;
}

.listTwo {
  width: 12%;
}

.listThree {
  width: 12%;
}

.listFour {
  width: 12%;
}

.listFive {
  width: 12%;
}

.listSix {
  width: 12%;
}

.listSeven {
  width: 28%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.audit {
  background: #f0a11f;
  margin-right: 4px;
}

.pass {
  color: #33ba78;
  margin-right: 4px;
  cursor: no-drop;
}

.fail {
  color: #ed4a47;
  margin-right: 4px;
  cursor: no-drop;
}

.look {
  background: #279de2;
  margin: 0 4px;
}

.edit {
  background: #279de2;
  margin: 0 4px;
}

.delect {
  background: #ed4a47;
  margin-left: 4px;
}
</style>